using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TCCT_CTC_CSDLDangVienV1
{
    public static partial class UI
    {

        public static void DateEdit_Closed(object sender, DevExpress.XtraEditors.Controls.ClosedEventArgs e)
        {
            if (e.CloseMode == PopupCloseMode.Normal)
            {
                System.DateTime tem = new System.DateTime();
                tem = frmBase.GetDateTime((DevExpress.XtraEditors.DateEdit)sender);
                if (tem == System.DateTime.MinValue)
                {
                    frmBase.SetValue((DevExpress.XtraEditors.DateEdit)sender, null);
                    return;
                }
                if (tem.Hour == 0 && tem.Minute == 0)
                {
                    tem = System.DateTime.Parse(tem.Month + "/" + tem.Day + "/" + tem.Year + " " + System.DateTime.Now.Hour + ":" + System.DateTime.Now.Minute + ":" + System.DateTime.Now.Second);

                    frmBase.SetValue((DevExpress.XtraEditors.DateEdit)sender, tem);
                }
            }
        }

        public static class DateTime
        {
            public const string FORMAT_DATE_SEQ = "ddMMyyyy";
            public const string FORMAT_DATE_VN = "dd/MM/yyyy";
            public const string FORMAT_DATE_TIME_VN = "dd/MM/yyyy HH:mm:ss";
            public const string FORMAT_dd_MM = "dd/MM";

            public static void ApplyDefault(DateEdit control, bool setNullValue)
            {
                control.Properties.DisplayFormat.FormatString = FORMAT_DATE_VN;
                control.Properties.EditMask = FORMAT_DATE_VN;
                control.Properties.NullDate = System.DateTime.MinValue;
                control.Properties.AppearanceReadOnly.BackColor = READ_ONLY_COLOR;
                if (setNullValue)
                    control.DateTime = System.DateTime.MinValue;
                control.EnterMoveNextControl = true;
                control.Properties.ReadOnly = false;
                control.BackColor = DEFAULT_BACKCOLOR;

                control.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.DateTimeAdvancingCaret;

            }
            public static void ApplyDefault(DateEdit control)
            {
                ApplyDefault(control, true);
            }
            public static void ApplyDefault(DevExpress.XtraEditors.Repository.RepositoryItemDateEdit control)
            {
                control.DisplayFormat.FormatString = FORMAT_DATE_VN;
                control.EditMask = FORMAT_DATE_VN;
                control.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.DateTimeAdvancingCaret;
                control.MinValue = System.DateTime.MinValue;

                //control.Closed += new DevExpress.XtraEditors.Controls.ClosedEventHandler(DateEdit_Closed);
            }

            public static void ApplyDateAndTime(DateEdit control, bool setNullValue)
            {
                ApplyDefault(control, setNullValue);
                control.Properties.DisplayFormat.FormatString = FORMAT_DATE_TIME_VN;
                control.Properties.EditMask = FORMAT_DATE_TIME_VN;
                control.Closed += new DevExpress.XtraEditors.Controls.ClosedEventHandler(DateEdit_Closed);
                //control.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True;
                //control.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True;
            }
            public static void ApplyDateAndTime(DateEdit control)
            {
                ApplyDateAndTime(control, true);
            }
            public static void ApplyDateAndTime(DevExpress.XtraEditors.Repository.RepositoryItemDateEdit control)
            {
                control.DisplayFormat.FormatString = FORMAT_DATE_TIME_VN;
                control.EditMask = FORMAT_DATE_TIME_VN;
                control.MinValue = System.DateTime.MinValue;
                control.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.DateTimeAdvancingCaret;
                control.Closed += new DevExpress.XtraEditors.Controls.ClosedEventHandler(DateEdit_Closed);
            }
        }
    }
}
